package com.our.sys.project1.web;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springside.modules.orm.Page;

import com.our.sys.project1.pojo.PriceReview;
import com.our.sys.project1.service.QueryService;

@Controller
@RequestMapping("/query_main")
public class QueryController {

    @Autowired
    private QueryService queryService;

    @RequestMapping(value = "/query_price_review")
    public @ResponseBody
    Map<String, Object> queryPriceReview(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        Page<PriceReview> page = new Page<PriceReview>(request);
        String orderColumn = request.getParameter("sort");
        String dir = request.getParameter("dir");
        if (StringUtils.isBlank(orderColumn)) {
            page.setOrderBy("discountDate");
            page.setOrder(Page.DESC);
        } else {
            page.setOrderBy(orderColumn);
            page.setOrder(dir);
        }

        String price = request.getParameter("price");
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        List<PriceReview> list = queryService.getPriceReview(new BigDecimal(price == null ? "0.00" : price), startTime,
                endTime, page);
        System.out.println(list.size());
        //自定义分页：
        //需要参数：1.每页显示数（默认20）2.第几页
        //☆☆☆☆这里固定使用sqlserver数据库分页
        //需要传递到页面数据：1.记录2.总记录数
        //Page<SupplierType> data = supplierService.queryType(page, filters);
        //map = AppUtil.buildJSONDataResponse(data.getResult(), (long) data.getTotalCount());
        return map;
    }
}
